import { Component, OnInit } from '@angular/core';
import { AxiosService } from '../../axios.service';
import { LocalStorageService } from 'src/app/myService/local-storage.service';
import { Router } from '@angular/router';
import { ActivatedRoute } from '@angular/router';
import { parse } from 'path';
import { THIS_EXPR } from '@angular/compiler/src/output/output_ast';
import { toNumber } from 'ng-zorro-antd';

@Component({
  selector: 'app-emp-zongjian',
  templateUrl: './emp-zongjian.component.html',
  styleUrls: ['./emp-zongjian.component.scss']
})
export class EmpZongjianComponent implements OnInit {

  isLoading;

  //所有工单数据
  public tempData = [];

  public listOfData = [];//工单文件区数据

  fileInfom;//显示工单对应的文件信息
  isOkLoadingfileInfom;

  public fileList;//选择要上传的文件
  public workName;
  uploader;
  fileName;//文件名
  workerName;//工件名
  link;
  workOrder;//上传对应的工单号
  sheet_order;//工件上传

  public unionorder: any;//工单号,
  public newValue: any;//"新值"
  name;//"表中栏位名称"

  addRemark1;//编辑设计备注
  isOkLoadingRemark;
  designRemark;

  splitJudge: string = ',';

  // 接收要修改的数据
  updateData;

  first: any;//首个19码
  tail: any;//结尾19码
  uploadData; // 上传数据

  public workData = [];
  //意同workData
  public dataWork = [];
  public selCNCData = [];

  isShow = [];
  btnStop = [];
  btnStart = [];

  value;//计时时间值
  totalTime;//数据库中的时间
  time;//页面的时间
  recordRowClick = -1;

  //其他备注
  addOtherRemark;
  isOkLoadingOthRemark;
  RemarkValue;//备注框的值
  workKey;

  showWarning = {};//工件行显示退回图标
  showBigWarning = [];//工单行显示退回图标

  isSendVisible;//送出工件
  isSendOkLoading;

  isFileVisible;//删除文件信息
  isFileOkLoading;
  id;//文件信息id


  timeIndex = 0;
  hour;
  minutes;
  seconds;
  timeKey: any = [];

  unionKey;
  smallKey;
  timeDic = {};

  // 总检状态
  allof = [];
  // 总检提醒
  alltitle = [];
  // 提交时间需要的字段
  timeid;
  timeunion_order;
  addTime = false;
  timetime;
  // 总监是否显示
  checkResult = false;
  NGnum;
  OKnum;
  alltimeunion_order;
  shows = [];

  ishowerer = [];
  sfmtime = "00:00:00"
  sjkg = false;
  kssj;
  jsq;
  noshow = 0;
  isshow = [];

  radioValue = '全部狀態'; // 默认筛选
  style = {
    display: 'block',
    height: '35px',
    width: '130px',
    lineHeight: '35px',
    padding: '0px 15px'
  };
  dlyy = [{
    name: "人為漏失", show: false
  }, { name: "人力不足", show: false }, { name: "加工不良", show: false }, { name: "缺料", show: false }, { name: "交期短", show: false }, { name: "需求變更", show: false }
    , { name: "待需求單位提供資料", show: false }, { name: "CNC產能不足", show: false }, { name: "待客戶驗證", show: false }]
  dlyynr;
  dlyysz = [];
  zjsj;
  zjng;
  zjok;
  min = 0;
  jobNo;
  listfd = [];
  //1號機台 2號機台 3號機台 4號機台
  selectStatus = [
    { 'name': 'ALL', 'checked': true, 'select': '' },
    { 'name': '1號機台', 'checked': true, 'select': '1號機 ' },
    { 'name': '2號機台', 'checked': true, 'select': '2號機 ' },
    // { 'name': '3號機台', 'checked': true, 'select': '3號機 ' },
    { 'name': '4號機台', 'checked': true, 'select': '4號機 ' },
    { 'name': '5號機台', 'checked': true, 'select': '5號機 ' },
    { 'name': '6號機台', 'checked': true, 'select': '6號機 ' },
    { 'name': '7號機台', 'checked': true, 'select': '7號機 ' },
    // { 'name': '8號機台', 'checked': true, 'select': '8號機 ' },
    { 'name': '9號 走芯機', 'checked': true, 'select': '9號 走芯機' }
  ];
  constructor(
    public axios: AxiosService,
    private storage: LocalStorageService,
    public activatedRoute: ActivatedRoute,
    private router: Router
  ) {
    this.activatedRoute.params.subscribe((data) => {
      if (data) {
        console.log("----------------------------\n", data)
        // this.nameTitle = data.name;
        // console.log(this.nameTitle)
      }
    })
  }

  ngOnInit(): void {
    //获取全部数据
    this.jobNo = this.storage.getStorageData('user').job_no;
    console.log(this.jobNo)
    this.getAllData();
  }
  //获取全部数据
  getAllData() {
    this.axios.axiosPost('QueryUnionOrderByStatusStage', { "stage": 6, "stageValue": 1, status: 6, 'job_no': this.jobNo })

      .then((data) => {
        if (data) {
          console.log(data)
          this.listfd = [];
          this.allof = [];
          this.alltitle = [];
          this.shows = [];
          this.isshow = [];
          this.ishowerer = [];
          this.tempData = data['order'];
          for (let i = 0; i < this.tempData.length; i++) {
            this.listfd.push(new Array)
            this.ishowerer.push(false)
            this.isshow.push(true)

            if (this.tempData[i].zongjian_ng_count == "" && this.tempData[i].zongjian_ok_count == "") {
              this.shows.push(true)
            } else {
              this.shows.push(false)
            }


            // 送检时间  或者NG  ok 数为空  显示  待品检
            if (this.tempData[i].songjian_time == "" && this.tempData[i].zongjian_ok_count == "" && this.tempData[i].zongjian_ng_count == "") {
              this.allof.push("0")
              // 有送检时间
            } else if (this.tempData[i].songjian_time != "") {

              // NG 不为空   OK 为空
              if (this.tempData[i].zongjian_ng_count != "" && this.tempData[i].zongjian_ok_count == "") {
                // 已品鉴/ng
                this.allof.push("2")

                //  NG 为 空   OK 不为空
              } else if (this.tempData[i].zongjian_ng_count == "" && this.tempData[i].zongjian_ok_count != "") {
                //  ok 数大于总数   显示 已品鉴
                if (parseInt(this.tempData[i].zongjian_ok_count) >= this.tempData[i].quatity) {
                  this.allof.push("3")
                } else {
                  // 小于   显示品鉴中
                  this.allof.push("1")
                }
                // ng   OK  都不空

              } else if (this.tempData[i].zongjian_ng_count != "" && this.tempData[i].zongjian_ok_count != "") {
                //如果ok >=总数
                if (parseInt(this.tempData[i].zongjian_ok_count) >= this.tempData[i].quatity) {

                  this.allof.push("3")

                } else {
                  this.allof.push("2")
                }

              } else {
                this.allof.push("1")
              }

            } else {
              // NG 不为空   OK 为空
              if (this.tempData[i].zongjian_ng_count != "" && this.tempData[i].zongjian_ok_count == "") {
                this.allof.push("2")
                //  NG 为 空   OK 不为空
              } else if (this.tempData[i].zongjian_ng_count == "" && this.tempData[i].zongjian_ok_count != "") {
                //  ok 数大于总数   显示 已品鉴
                if (parseInt(this.tempData[i].zongjian_ok_count) >= this.tempData[i].quatity) {
                  this.allof.push("3")
                } else {
                  // 小于   显示品鉴中
                  this.allof.push("1")
                }
                // ng   OK  都不空

              } else if (this.tempData[i].zongjian_ng_count != "" && this.tempData[i].zongjian_ok_count != "") {
                //ok >=总数
                if (parseInt(this.tempData[i].zongjian_ok_count) >= this.tempData[i].quatity) {
                  this.allof.push("3")
                } else {
                  this.allof.push("2")
                }

              } else {
                this.allof.push("0")
              }
            }


            // 无送检时间  不显示
            if (this.tempData[i].songjian_time == "") {
              this.alltitle.push(false)
            } else {
              // 送检时间当天的四点半
              var shijian = this.tempData[i].songjian_time.substring(0, 10) + " 16:30:00"
              var ay = Number(new Date().getMonth()) + 1 < 10 ? "0" + (Number(new Date().getMonth()) + 1) : new Date().getMonth() + 1;
              var ar = Number(new Date().getDate()) < 10 ? "0" + new Date().getDate() : new Date().getDate();
              var as = new Date().getFullYear() + "/" + ay + "/" + ar
              // 当下时间的四点半
              var sj = as + " 16:30:00";
              var sj0 = as + " 00:00:00";
              var sj4 = Number(new Date().getTime()) - 86400000
              console.log("送检那天四点半" + shijian + "-----------------------" + new Date(shijian).getTime())
              console.log("当下时间的四点半" + sj + "-----------------------" + new Date(sj).getTime())
              console.log("送检时间" + "-----------------------" + this.tempData[i].songjian_time + new Date(this.tempData[i].songjian_time).getTime())
              console.log("当下日期-86400000" + "-----------------------" + sj4)
              console.log("当下日期 00:00:00" + sj0 + "-----------------" + new Date(sj0).getTime())
              // 有送检时间判断 是否地雷
              // 判断   送检时间  是送检那天四点半前还是四点半后  且状态是总检中
              // 送检时间是四点半前 ↓
              if (new Date(shijian).getTime() >= new Date(this.tempData[i].songjian_time).getTime()) {
                console.log("送检时间小于送检送检那天四点半")
                // 送检时间和实际当天的四点半时间进行对比
                // 如果小于  显示Delay
                if (new Date(this.tempData[i].songjian_time).getTime() <= new Date(sj).getTime() && new Date(this.tempData[i].songjian_time).getTime() >= new Date(sj0).getTime()) {
                  console.log("送检时间小于当天下午四点半,且大于当天00:00:00")
                  if (new Date().getTime() <= new Date(sj).getTime()) {
                    console.log("当下时间为四点半前")
                    this.alltitle.push(false)
                  } else {
                    console.log("当下时间为四点半后")
                    this.alltitle.push(true)
                  }
                } else if (new Date(this.tempData[i].songjian_time).getTime() >= new Date(sj).getTime()) {
                  console.log("送检时间大于今天下午四点半")
                  this.alltitle.push(false)
                } else {
                  console.log("送检时间大于当天下午四点半或者小于当天00:00:00")
                  this.alltitle.push(true)
                }
              } else {
                //四点半之后的订单;
                // 当前时间+86400000 是否大于 送检日期的时间戳
                console.log("送检时间大于送检当天四点半")
                if (sj4 > new Date(shijian).getTime()) {
                  console.log("当下时间减去一天大于送检当天的四点半")
                  this.alltitle.push(true)
                } else {
                  console.log("当下时间减去一天小于送检当天的四点半")
                  this.alltitle.push(false)
                }
              }
            }

            if (this.tempData[i].tip > 0) {
              this.showBigWarning.push(true);
            } else {
              this.showBigWarning.push(false);
            }
          }
          console.log(this.alltitle)
          console.log(this.allof)
          this.storage.setStorageData('result', this.tempData);
          // this.QueryWorkOrder();
        }
      })
      .catch((err) => {
        console.log(err);
      })
  }

  //查询工单对应的工件信息
  QueryWorkOrder(key) {
    this.unionKey = key;
    this.workKey = key;
    this.axios.axiosPost('QueryWorkOrder', { 'unionorder': this.tempData[key].union_order, "status": 6 })
      .then((data) => {
        console.log(data)
        if (data['result'] === 'ok' && data['order'].length > 0) {
          // debugger
          const orderData = data['order'];
          this.listfd[key] = new Array;
          //过滤标准件，只显示加工件
          let a = data['order'].filter((item, i) => { return item.type_flag != 0; })
          this.workData[key] = a;
          this.dataWork = a;
          console.log(this.workData)
          const tempArr = [];
          const timeDefault = [];
          for (let i = 0; i < orderData.length; i++) {
            this.listfd[key].push(new Array)
            if (orderData[i]['remark'] !== '') {
              tempArr.push(true);
            } else {
              tempArr.push(false);
            }

            // 给点击的小行数据初始化时间
            timeDefault.push('');
          }
          this.showWarning[key] = tempArr;
          this.timeDic[this.unionKey] = timeDefault;
          console.log('1111111\n', this.showWarning)
        }
      })
      .catch((err) => {
        console.log(err);
      })
  }

  //CNC机台选择
  selStatus(item) {
    item.checked = !item.checked;
    this.selCNC(item);
  }

  //筛选CNC机台
  selCNC(data) {

    if (data.checked) {
      const addCNC = this.dataWork.filter(res => res['cnc_name'] === data.select);
      console.log(addCNC)
      this.selCNCData = this.selCNCData.concat(addCNC);
      console.log(this.selCNCData)
    }
    // 未选中
    if (!data.checked) {
      const deleteCNC = this.workData.filter(res => res['cnc_name'] === data.select);
      console.log(deleteCNC)
      this.selCNCData = this.workData.filter(item => !deleteCNC.some(ele => ele['cnc_name'] === item['cnc_name']));
      console.log(this.selCNCData)
    }
    // this.workData = [];
    this.workData = this.selCNCData;
  }

  //点击设计备注
  addRemark(item) {
    this.addRemark1 = true;
    this.designRemark = item.zongjian_beizhu;
    this.updateData = item;
    // if (item.zongjian_beizhu.split(",")) {
    //   this.dlyysz = item.zongjian_beizhu.split(",");
    //   for (var i = 0; i < this.dlyysz.length; i++) {
    //     for (var y = 0; y < this.dlyy.length; y++) {
    //       if (this.dlyysz[i] == this.dlyy[y].name) {
    //         this.dlyy[y].show = true;
    //       }
    //     }
    //   }
    // }
  }
  //确认添加设计备注
  addRemarkOk() {
    this.isOkLoadingRemark = true;
    this.addRemark1 = false;
    this.isOkLoadingRemark = false;
    this.axios.axiosPost('UpdateUnionOrder', { 'unionorder': this.updateData.union_order, 'name': 'zongjian_beizhu', 'newValue': this.designRemark })
      .then((data) => {
        console.log(data)
        if (data['result'] === 'ok') {
          this.getAllData();
        }
      })
  }

  //取消添加设计备注
  CancelAddRemark() {
    this.addRemark1 = false;
    // for (var i = 0; i < this.dlyy.length; i++) {
    //   this.dlyy[i].show = false
    // }
  }
  bzclick(name) {
    console.log(name)
    console.log(this.dlyy)
    this.dlyysz = []
    for (var i = 0; i < this.dlyy.length; i++) {
      if (this.dlyy[i].show == true) {
        this.dlyysz.push(this.dlyy[i].name)
      }
    }
    this.dlyynr = this.dlyysz.join(",")
    console.log(this.dlyynr)
  }

  currentPageDataChange(qqq) {

  }

  //点击图标显示此工单的文件信息
  downLoad(infom) {
    console.log(infom)
    this.fileInfom = true;
    // this.updateData = infom;
    // debugger
    this.workOrder = infom.union_order;
    this.workerName = infom.name;
    this.workName = this.workOrder;
    this.sheet_order = infom.sheet_order;
    console.log(infom.name, this.workOrder)
    if (infom.name !== undefined) {
      this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': infom.name })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.listOfData = data['files'];
          }
        })
    } else if (infom.name === undefined) {
      this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.sheet_order })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.listOfData = data['files'];
          }
        })
    }
  }

  CancelShow() {
    this.fileInfom = false;
  }

  ShowOK() {
    this.isOkLoadingfileInfom = true;
    this.fileInfom = false;
    this.isOkLoadingfileInfom = false;
  }

  //上传文件
  Upload() {
    // debugger
    if (this.uploadData == null)
      return;
    console.log(this.workOrder, this.workerName)
    if (this.workerName !== undefined) {
      this.isLoading = true;
      this.axios.axiosPost('Upload', {
        'unionorder': this.workOrder, 'workorder': this.workerName,
        'filename': this.fileName.files[0]['name'], 'filedata': this.uploadData
      })
        .then((data) => {

          console.log(data)
          if (data['result'] === 'ok') {
            this.isLoading = false;
            alert("上传成功！")
            this.uploadData = null;
            this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.workerName })
              .then((data) => {
                if (data['result'] === 'ok') {
                  this.listOfData = data['files'];
                }
              })

          } else {
            this.isLoading = false;
            alert(data["description"])
          }
        }).catch(function (err) {
          console.log(err)
        })
    } else if (this.workerName === undefined) {
      this.isLoading = true;
      this.axios.axiosPost('Upload', {
        'unionorder': this.workOrder, 'workorder': this.sheet_order,
        'filename': this.fileName.files[0]['name'], 'filedata': this.uploadData
      })
        .then((data) => {

          console.log(data)
          if (data['result'] === 'ok') {
            this.isLoading = false;
            alert("上传成功！")
            this.uploadData = null;
            this.axios.axiosPost('QueryWorkFiles', { 'unionorder': this.workOrder, 'workorder': this.sheet_order })
              .then((data) => {
                if (data['result'] === 'ok') {
                  this.listOfData = data['files'];
                }
              })

          } else {
            this.isLoading = false;
            alert(data["description"])
          }
        }).catch(function (err) {
          console.log(err)
        })
    }
  }

  //选择要上传的文件名
  openFile(event: any): void {
    // debugger
    this.fileName = event.target; //获取点击得到的对象
    const reader = new FileReader();
    reader.onload = (() => {
      if (reader.result) {
        this.uploadData = reader.result;
        console.log(reader.result);
      }
    });
    reader.readAsDataURL(this.fileName.files[0]);//将文件转为Base64格式
    console.log("hahahaahahahah\n", reader.result)
  }

  handleFileCancel() {
    this.isFileVisible = false;
  }

  downLoadFile(data) {
    console.log(data)
    // debugger
    this.fileName = data.file_name;
    this.link = this.axios.domainTest1 + this.workName + '/' + this.fileName;
    console.log(this.fileName, this.link)
  }

  //删除文件信息
  showDelFile(data) {
    this.isFileVisible = true;
    console.log(data)
    this.id = data.id;
  }

  delFileOk() {
    this.isFileOkLoading = true;
    this.isFileVisible = false;
    this.isFileOkLoading = false;
    this.axios.axiosPost('DeleteWorkFile', { 'id': this.id })
      .then((data) => {
        console.log(data)
        if (data['result'] === 'ok') {
          let listData = this.listOfData.filter(res => res['id'] !== this.id)
          this.listOfData = listData;
        }
      })
  }
  //退回工件
  return(item) {
    if (!item.priority) {
      this.unionorder = item.union_order;
      this.addOtherRemark = true;
      this.RemarkValue = item.other_remark + this.storage.getStorageData('user').name + ":"
    } else {
      alert("該工單未停止計時")
    }
  }

  //取消备注
  CancelRemark() {
    this.addOtherRemark = false;
  }

  //添加其他备注（退回）
  RemarkOk() {
    if (this.RemarkValue.length != 0) {
      // debugger
      this.isOkLoadingOthRemark = true;
      this.addOtherRemark = false;
      this.isOkLoadingOthRemark = false;
      let content = '';
      content = this.RemarkValue;//姓名+内容
      console.log(content)
      this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "other_remark", "newValue1": this.RemarkValue }).then((data) => {
        console.log(data)
      })
      this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 5, "stageValue": 1, "newValue12": 6, "stageValue2": 0 }).then((data) => {
        console.log(data, "工单状态修改成功了,取消了当前工单状态")
      })

      this.axios.axiosPost('UpdateWorkOrder', {
        'unionorder': this.unionorder, 'status': 5
      })
        .then((data) => {
          console.log(data)
          if (data['result'] === 'ok') {
            this.getAllData();

          }
        })
        .catch((err) => {
          console.log(err);
        })
    } else {
      alert("請輸入退單備註")
    }
  }
  //点击工单号显示CNC
  showCNC(item) {
    debugger
    console.log(item)
    const data = {};
    data['union_order'] = item.union_order;
    this.router.navigate(['/CNC', data])
  }

  //送出按钮
  send(item) {
    console.log(item)
    if (!item.priority) {

      this.isSendVisible = true;
      this.unionorder = item.union_order;
      this.workerName = item.sheet_order;
      this.zjsj = item.songjian_time;
      this.zjok = item.zongjian_ok_count;
      this.zjng = item.zongjian_ng_count
      // this.ngjg=item.
    } else {
      alert("該工單未停止計時")
    }
  }

  //取消送出
  handleSendCancel() {
    this.isSendVisible = false;
  }

  //确认送出
  sendOk() {
    if (this.zjsj) {
      if (this.zjok || this.zjng) {
        this.isSendOkLoading = true;
        this.isSendVisible = false;
        this.isSendOkLoading = false;
        this.axios.axiosPost("UpdateUnionOrder2", { 'unionorder': this.unionorder, "name1": "stage", "newValue1": 6, "stageValue": 0, "newValue12": 7, "stageValue2": 1, "name2": "status", "newValue2": 1 }).then((data) => {
          console.log(data, "工单状态修改成功了,取消了当前工单状态")
        })

        this.axios.axiosPost('UpdateWorkOrder', {
          'unionorder': this.unionorder, 'status': 7
        })
          .then((data) => {
            console.log(data)
            if (data['result'] === 'ok') {
              this.getAllData();

            }
          })
          .catch((err) => {
            console.log(err);
          })
      } else {
        alert("未填寫總鑒結果")
      }
    } else {
      alert("未填寫送檢時間")
    }
  }


  btn_CNC(data) {
    console.log(data)
    const CNCnum = {};
    CNCnum['select'] = data.select;
    console.log(CNCnum['select'])
    this.router.navigate(['/CNC', CNCnum]);
  }
  addDate(item) {
    console.log(item)
    this.timeid = item.id;
    this.timeunion_order = item.union_order;
    this.sheet_order = item.sheet_order;
    this.addTime = true;
    var showTime = new Date();
    let year = showTime.getFullYear();
    let mon = showTime.getMonth() + 1 < 10 ? "0" + (showTime.getMonth() + 1) : showTime.getMonth() + 1;;
    let da = showTime.getDate() < 10 ? "0" + showTime.getDate() : showTime.getDate();
    let hour = showTime.getHours() < 10 ? "0" + showTime.getHours() : showTime.getHours();
    let munite = showTime.getMinutes() < 10 ? "0" + showTime.getMinutes() : showTime.getMinutes();
    this.timetime = year + '/' + mon + '/' + da + ' ' + hour + ':' + munite;
  }
  //取消添加时间
  CancelAddTime() {
    this.addTime = false;
  }

  //确定添加时间
  addTimeOk() {
    this.addTime = false;
    this.axios.axiosPost('UpdateUnionOrder2', { 'unionorder': this.timeunion_order, name1: 'songjian_time', newValue1: this.timetime }).then((data) => {
      this.getAllData();
    })
  }


  //点击添加检测结果
  addResultNum(data) {
    this.alltimeunion_order = data.union_order
    this.checkResult = true;
    this.NGnum = data.zongjian_ng_count
    this.OKnum = data.zongjian_ok_count
    console.log(data, this.NGnum, this.OKnum)

  }

  //取消添加工件检测结果
  CancelAddResult() {
    this.checkResult = false;
  }
  addCheckResult() {
    this.checkResult = false;
    if (this.OKnum == undefined) {
      this.OKnum = 0;
    }
    if (this.NGnum == undefined) {
      this.NGnum = 0;
    }
    this.axios.axiosPost('UpdateUnionOrder2', { 'unionorder': this.alltimeunion_order, name1: 'zongjian_ok_count', newValue1: this.OKnum, name2: 'zongjian_ng_count', newValue2: this.NGnum }).then((data) => {
      this.getAllData();
    })

  }
  //点击行显示计时器
  clickLine(key, item2) {
    console.log(item2);
    console.log(new Date().getTime());

    for (var i = 0; i < this.ishowerer.length; i++) {
      if (this.ishowerer[i] == true && i != key) {
        this.min++;
      }
    }
    if (this.min == 0) {
      this.ishowerer[key] = true;
      this.min = 0;
      if (item2) {
        this.jsq = setInterval(() => {
          // console.log(new Date().getTime() - item2);
          this.sfmtime = this.timeof(new Date().getTime() - item2 * 1000);
        }, 1000);
      } else {
        this.sfmtime = "00:00:00"
      }
    } else {
      this.ishowerer[key] = false;
      this.min = 0;
    }
    // console.log(this.ishowerer);

  }

  //开始计时
  start(item, key) {

    if (this.sjkg == false) {
      this.sjkg = true;
      if (this.sfmtime == "00:00:00") {
        this.axios.axiosPost("UpdateUnionOrder", {
          unionorder: item.union_order,
          name: "priority",
          newValue: new Date().getTime() / 1000,
        }).then((data) => {
          console.log(data);
          this.tempData[key].priority = new Date().getTime() / 1000
          this.clickLine(key, item.priority)
        })
      } else {
        alert("已經開始計時了")
      }
    } else {
      alert("已經開始計時，請勿重復操作")
    }
    // console.log(key)
    // this.btnStop[key] = true;
    // this.btnStart[key] = false;
    // console.log('00000000000000 \n', this.btnStart)
    // // this.setTime();
    // // timeIndex = 0;
    // console.log(item.sheji_shijian)
    // this.value = setInterval(setTime, 1000);
  }

  //结束计时
  end(item, key) {
    if (item.priority || this.sfmtime != "00:00:00") {
      clearInterval(this.jsq);
      this.ishowerer[key] = false;
      this.min = -1;
      this.sjkg = false;
      this.axios
        .axiosPost("AddWorkTime", {
          unionorder: item.union_order,
          endtime: new Date().getTime(),
          stage: 6,
        })
        .then((data) => {
          console.log(data);
          if (data["result"] === "ok") {
            console.log(this.tempData[key]);
            this.tempData[key].priority = "";
            console.log("真棒");
            this.sfmtime = "00:00:00";
            this.getAllData();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    } else {
      alert("此工單未開始計時")
    }

    // this.btnStart[key] = false;
    // this.btnStop[key] = true;
    // // debugger
    // if (item.sheji_shijian === '') {
    //   item.sheji_shijian = 0;
    //   this.totalTime = item.sheji_shijian;
    // } else {
    //   this.totalTime = item.sheji_shijian;
    // }
    // console.log(this.totalTime)
    // // debugger
    // console.log(item, document.getElementsByClassName('sp')[0].innerHTML)
    // this.time = document.getElementsByClassName('sp')[0].innerHTML;
    // var hour = this.time.split(':')[0];
    // var min = this.time.split(':')[1];
    // var sec = this.time.split(':')[2];
    // var s;
    // s = Number(hour * 3600) + Number(min * 60) + Number(sec);
    // // var total;
    // // total =  parseInt(this.totalTime) + s;
    // // console.log(total,parseInt(this.totalTime))
    // this.recordRowClick = -1;
    // clearInterval(this.value);
    // this.value = null;

    // console.log('11111111111\n', this.isShow)
  }
  timeof(data) {
    var s;
    var hours: number;
    // hours=parseInt((1000 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    hours = parseInt((data % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)).toString())
    // parseInt((1000 % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
    console.log(hours)
    var minutes = parseInt(((data % (1000 * 60 * 60)) / (1000 * 60)).toString());
    var seconds = parseInt(((data % (1000 * 60)) / 1000).toString());
    s = (hours < 10 ? ('0' + hours) : hours) + ':' + (minutes < 10 ? ('0' + minutes) : minutes) + ':' + (seconds < 10 ? ('0' + seconds) : seconds);
    console.log(s)
    return s;
  }

  //结束页面生命周期
  ngOnDestroy(): void {
    //Called once, before the instance is destroyed.
    //Add 'implements OnDestroy' to the class.
    clearInterval(this.jsq);

  }
  //筛选治具状态
  doingForm() {
    console.log(this.radioValue)
    console.log(this.allof)
    if (this.radioValue === '全部狀態') {
      this.getAllData();
    } else if (this.radioValue === '待總檢') {
      for (var i = 0; i < this.allof.length; i++) {
        if (this.allof[i] == 0) {
          this.isshow[i] = true
        } else {
          this.isshow[i] = false;
        }
      }
    } else if (this.radioValue === '總檢中') {
      for (var i = 0; i < this.allof.length; i++) {
        if (this.allof[i] == 1) {
          this.isshow[i] = true
        } else {
          this.isshow[i] = false;
        }
      }

    } else if (this.radioValue === '已總檢') {
      for (var i = 0; i < this.allof.length; i++) {
        if (this.allof[i] == 3) {
          this.isshow[i] = true
        } else {
          this.isshow[i] = false;
        }
      }
    } else if (this.radioValue === '已總檢/NG') {
      for (var i = 0; i < this.allof.length; i++) {
        if (this.allof[i] == 2) {
          this.isshow[i] = true
        } else {
          this.isshow[i] = false;
        }
      }
    }
  }
  QueryWorkOrder2(a, b, c) {
    console.log("触发", a)
    this.axios.axiosPost("QueryCncDataSubOrder", { "unionorder": a.unionorder, "workorder": a.workorder, status: 6 }).then((data) => {
      console.log(data);
      if (data["result"] == "ok") {
        this.listfd[b][c] = data["order"];
      }
    })
  }
}
